<template>
    <button type="button" :class="{'codegray':time > 0}"  :disabled="time > 0">{{ text }}</button>
</template>
<script>
    export default {
            props: {
                second: {
                    type: Number,
                    default: 60
                },
                btntext: {
                    type: String
                }
            },
            data() {
                return {
                    time: 0
                }
            },
            methods: {
                send() {
                    this.time = this.second
                    this.timer()
                    this.$emit('send')
                },
                timer() {
                    if (this.time > 0) {
                        this.time = this.time - 1;                  
                        setTimeout(this.timer, 1000)
                    }
                }
            },
            computed: {
                text() {
                    return this.time > 0 ? this.time + 's后再次获取' : this.btntext;
                }
            }
        }

</script>
